#include <iostream>
#include "namepipe.hpp"

int main()
{
    namepipe pipe(gpathname, gCreat);  //管理者创建管道
    if (gDefault != pipe.OpenPipeRead())  //打开管道读端
    {
        while (true)
        {
            std::string message;
            int n = pipe.GetMassage(&message); //获取管道数据
            if (n > 0)
            {
                std::cout << "Get massage> " << message << std::endl;
            }
            else if (n == 0)  //读到0表示写端已经退出，则读端也可以退出
            {
                std::cout << "Deliver quit , server quit too ! " << message << std::endl;
                break;
            }
            else
            {
                std::cout << "GetMassage Error, server quit!";
                break;
            }
        }
    }
    return 0;
}